<?php
	namespace Home\Controller;
	use Think\Controller;
		class OrderController extends Controller{
			public function index(){
				layout('layout/layout');
				$order = M("homeuser");
				$map['homeuser.id'] = array('eq',$_GET['id']);
				$Page = new \Think\Page($count,5);// 实例化分页类 传入总记录数和每页显示的记录数(5)
				$show = $Page->show();// 分页显示输出
				$list=$order
					->field('`order`.status valstatus,homeuser.*,orderdetail.*,goodsdetail.*,spu_sku.*,shop_goods.*,shop.*,order_status.*')
					->join('`order` on homeuser.id = order.uid','left')
					->join('order_status on order.status=order_status.statusid','left')
					->join('orderdetail on order.id = orderdetail.orderid','left')
					->join('goodsdetail on orderdetail.skuid = goodsdetail.skuid','left')
					->join('spu_sku on goodsdetail.skuid = spu_sku.skuid','left')
					->join('shop_goods on spu_sku.spuid = shop_goods.spuid','left')
					->join('shop on shop_goods.shopid=shop.id','left')
					->where('homeuser.id=1')->limit($Page->firstRow.','.$Page->listRows)->select();
				$this->assign('list',$list);
				$this->assign('page',$show);
				$this->display();	
			}
			public function orderdetail(){
				layout('layout/layout');
				$map['order.id']=array('eq',$_GET['id']);
				$order = M("homeuser");
				$vo=$order->join('`order` on homeuser.id = order.uid','left')->join('orderdetail on order.id = orderdetail.orderid','left')->join('goodsdetail on orderdetail.skuid = goodsdetail.skuid','left')->join('spu_sku on goodsdetail.skuid = spu_sku.skuid','left')->join('shop_goods on spu_sku.spuid = shop_goods.spuid','left')->join('shop on shop_goods.shopid=shop.id','left')->join('buyaddress on homeuser.id=buyaddress.uid','left')->where($map)->select();
				$this->assign('vo',$vo);
				$this->display();
			}
			public function search(){
				$search = M('order');
				$keyword = $_POST['search'];
				$option = $_POST['option'];
				// $where['orderdetail.orderid|goodsdetail.goodsname']=array('like','%'.$keyword.'%');
				// $where['order_status.statusid']=array('eq',$option);
				// $where['_LOGIC']= 'and';
				// $map['_complex']=$where;
				$where = ['order_status.statusid'=>['eq',$option],'_complex'=>['orderdetail.orderid|goodsdetail.goodsname'=>['like','%'.$keyword.'%']]];
				$list=$search
					->join('orderdetail on `order`.id = orderdetail.orderid','left')
					->join('goodsdetail on orderdetail.skuid = goodsdetail.skuid','left')
					->join('spu_sku on goodsdetail.skuid=spu_sku.skuid','left')
					->join('shop_goods on spu_sku.spuid=shop_goods.spuid','left')
					->join('shop on shop_goods.shopid=shop.id','left')
					->join('order_status on order.status=order_status.statusid','left')
					->where($where)->select();
					var_dump($where);
				if($list){
					$this->assign('list',$list);
					$this->display('order/search');
				}else{
					echo 0;}
			}
		
		}